﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AcademicPlanner.Presentation
{
	/// <summary>
	/// Labels is a static class for storage and retrieval of labels (mostly form related).
	/// </summary>
	/// <version>1.0</version>
	/// <since>1.0</since>
	public static class Labels
	{
		private static Dictionary<string, string> labels;
		private static string separator = "_";

		private static void Init()
		{
			labels = new Dictionary<string, string>();

			labels.Add("Person_Email", "Email");
			labels.Add("Person_Name", "Name");
			labels.Add("User_Name", "Username");
			labels.Add("User_Password", "Password");
			labels.Add("User_RepeatedPassword", "Repeat Password");
		}

		/// <summary>
		/// Gets the label text of a <code>Model</code>'s property.
		/// </summary>
		/// <param name="pProperty">The name of the property whose label to get.</param>
		/// <param name="pModel">The name of the <code>Model</code> the property belongs to.</param>
		/// <returns>The property's label; the property name if nothing was found
		/// in the storage.</returns>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public static string Get(string pProperty, string pModel)
		{
			if (labels == null) Init();

			string rVal = pProperty;
			string vKey = string.IsNullOrEmpty(pModel) ? pProperty : pModel + separator + pProperty;

			labels.TryGetValue(vKey, out rVal);
			if (rVal == null) rVal = pProperty;

			return rVal;
		}

		/// <summary>
		/// Gets the label text of a property. This method is a convenience overload of
		/// <see cref="M:Get(string, string)"/> with the second parameter null.
		/// </summary>
		/// <param name="pProperty">The name of the property whose label to get.</param>
		/// <returns>The property's label.</returns>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public static string Get(string pProperty)
		{
			return Get(pProperty, null);
		}
	}
}
